package encounter;

import main.Hero;
import main.Logger;

public class FallenHeroEncounter implements Encounter {
    private final Hero fallenHero;

    public FallenHeroEncounter(Hero fallenHero) {
        this.fallenHero = fallenHero;
    }

    @Override
    public boolean resolve(Hero hero) {
        Logger.log(hero + " comes upon fallen " + fallenHero + ".");
        hero.addEvent("Comes upon fallen " + fallenHero);
        hero.updateEnergy(-0.01);

        if (fallenHero.isDeceased()) {
            Logger.log(fallenHero + " is deceased.");
            Logger.log(hero + " takes items and copper from " + fallenHero);
            
            int copper = fallenHero.getCopper();
            hero.updateCopper(copper);
            fallenHero.updateCopper(-copper);

            fallenHero.getItems().forEach(hero::addItem);
            fallenHero.getItems().clear();

            return true;
        } else {
            return hero.rescue(fallenHero);
        }
    }

}
